//
//  PhoneCallViewController.m
//  HelloTaxi
//
//  Created by ss ss on 8/1/12.
//  Copyright (c) 2012 ECUST. All rights reserved.
//

#import "PhoneCallViewController.h"
#import "PhoneCallCell.h"
#include "PhoneInfo.h"


@interface PhoneCallViewController ()

@end

@implementation PhoneCallViewController
@synthesize table;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.table.delegate = self;
    self.table.dataSource = self;
}

- (void)viewDidUnload
{
    [self setTable:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [table release];
    [super dealloc];
}


#pragma mark - UITableViewDelegate, UITableViewDataSource

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int number = sizeof(shanghai) / sizeof(PhoneInfo);
    return number;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"phoneCallCell";
    PhoneCallCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    
//    if (cell == nil)  
//    {  
//        // Create a cell to display an ingredient.  
//        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle   
//                                       reuseIdentifier:CellIdentifier]   
//                autorelease];  
//    }  
    
    
    
    int32_t index = indexPath.row;

    NSString* name = [NSString stringWithUTF8String:shanghai[index].name];
    cell.titleLabel.text = name;
    cell.phoneNumLabel.text = [NSString stringWithUTF8String:shanghai[index].number];
    
    //cell.textLabel.text = [NSString stringWithFormat:@"%@: %s", name, shanghai[index].number];
    
    // Configure the cell...
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    int index = indexPath.row;
    NSString* str = [NSString stringWithFormat:@"%s", shanghai[index].number];
    if (str.length > 0) {
        NSString* phone = [@"telprompt://" stringByAppendingString:str];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phone]];
    }
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 65;
//}


@end
